package com.guxingke.typecho4j.widget.provider.comment;

import java.util.List;

import com.guxingke.typecho4j.jfinal.model.Comment;
import com.guxingke.typecho4j.util.PageBean;
import com.guxingke.typecho4j.util.PageUtil;
import com.guxingke.typecho4j.widget.WidgetProvider;
import com.guxingke.typecho4j.widget.provider.CommentBaseWidget;
import com.jfinal.core.Controller;

/**
 * 内容评论组件，对应某post,page的评论数据
 * 
 * @author guxingke
 * */
public class CommentsManageWidget extends CommentBaseWidget implements
		WidgetProvider {

	@Override
	public void excute(Controller controller) {
		Integer page = controller.getParaToInt("page");
		if (page == null) {
			page = 1;
		}
		List<Comment> comments = null;

		comments = getComments(new PageBean(page,
				constants.getPageSize()));
		controller.setAttr("comments", comments);

		Long commentsNum = getCommentsNum();
		String pageNav = PageUtil.getPagation(constants.getSiteUrl()
				+ "/admin/manage-comments",
				(int) (long) commentsNum, page,
				constants.getPageSize());
		controller.setAttr("pageNav", pageNav);
	}

	@Override
	public void refresh() {
	}
}
